package com.ruoyi.patrol.controller;

import java.io.IOException;
import java.util.List;

import com.ruoyi.common.utils.getHardwareinfo.API;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.patrol.domain.PtDevice;
import com.ruoyi.patrol.service.IPtDeviceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备Controller
 * 
 * @author lkm
 * @date 2024-12-05
 */
@RestController
@RequestMapping("/patrol/device")
public class PtDeviceController extends BaseController
{
    @Autowired
    private IPtDeviceService ptDeviceService;

    /**
     * 查询设备列表
     */
    @PreAuthorize("@ss.hasPermi('patrol:device:list')")
    @GetMapping("/list")
    public TableDataInfo list(PtDevice ptDevice)
    {
        startPage();
        List<PtDevice> list = ptDeviceService.selectPtDeviceList(ptDevice);
        return getDataTable(list);
    }

    /**
     * 导出设备列表
     */
    @PreAuthorize("@ss.hasPermi('patrol:device:export')")
    @Log(title = "设备", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PtDevice ptDevice)
    {
        List<PtDevice> list = ptDeviceService.selectPtDeviceList(ptDevice);
        ExcelUtil<PtDevice> util = new ExcelUtil<PtDevice>(PtDevice.class);
        return util.exportExcel(list, "device");
    }

    /**
     * 获取设备详细信息
     */
    @PreAuthorize("@ss.hasPermi('patrol:device:query')")
    @GetMapping(value = "/{deviceId}")
    public AjaxResult getInfo(@PathVariable("deviceId") Long deviceId)
    {
        return AjaxResult.success(ptDeviceService.selectPtDeviceById(deviceId));
    }

    /**
     * 新增设备
     */
    @PreAuthorize("@ss.hasPermi('patrol:device:add')")
    @Log(title = "设备", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PtDevice ptDevice)
    {
        return toAjax(ptDeviceService.insertPtDevice(ptDevice));
    }

    /**
     * 修改设备
     */
    @PreAuthorize("@ss.hasPermi('patrol:device:edit')")
    @Log(title = "设备", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PtDevice ptDevice)
    {
        return toAjax(ptDeviceService.updatePtDevice(ptDevice));
    }

    /**
     * 删除设备
     */
    @PreAuthorize("@ss.hasPermi('patrol:device:remove')")
    @Log(title = "设备", businessType = BusinessType.DELETE)
	@DeleteMapping("/{deviceIds}")
    public AjaxResult remove(@PathVariable Long[] deviceIds)
    {
        return toAjax(ptDeviceService.deletePtDeviceByIds(deviceIds));
    }

    /**
     * 比赛第二套方案
     */
    @GetMapping("/police/{parameter}")
    public void police(@PathVariable String parameter){
        try {
//            API.updateDevice(parameter);
            API.policeDevice(parameter);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
